import 'package:flutter/material.dart';
import 'package:myflutter/DrawerPage/MyDrawerPageWidget.dart';
import 'package:myflutter/Moudles/MainFindsPage.dart';
import 'package:myflutter/Moudles/MainHomePage.dart';
import 'package:myflutter/Moudles/MainMinePage.dart';
import 'package:myflutter/Moudles/MainNewPage.dart';
// import 'package:myflutter/widgets/Navigation_icon_view.dart';


class MainPageWidget extends StatefulWidget {
  @override
  _MainPageWidgetState createState() => _MainPageWidgetState();

}

class _MainPageWidgetState extends State<MainPageWidget> {
  
  final _appBarTitle = ["资讯","动态","发现","我的"];

  // List <MyNavigationIconView> _navigationView;

  // List <BottomNavigationBarItem> _barNavigationView;
  
  var _currentIndex = 0;

  List<Widget> _pages;

  PageController _pageController;

  @override
  void initState() {

    super.initState();

    // _navigationView = [
    //   MyNavigationIconView(
    //       myTitle: '资讯',
    //       iconPath: 'assets/images/ic_nav_news_normal.png',
    //       actionIconPath: 'assets/images/ic_nav_news_actived.png'),
    //   MyNavigationIconView(
    //       myTitle: '动态',
    //       iconPath: 'assets/images/ic_nav_tweet_normal.png',
    //       actionIconPath: 'assets/images/ic_nav_tweet_actived.png'),
    //   MyNavigationIconView(
    //       myTitle: '发现',
    //       iconPath: 'assets/images/ic_nav_discover_normal.png',
    //       actionIconPath: 'assets/images/ic_nav_discover_actived.png'),
    //   MyNavigationIconView(
    //       myTitle: '我的',
    //       iconPath: 'assets/images/ic_nav_my_normal.png',
    //       actionIconPath: 'assets/images/ic_nav_my_pressed.png'),
    // ];

    _pages = [
      MainHomePageWidget(),
      MainNewPageWidget(),
      MainFindPageWidget(),
      MainMinePageWidget(),
    ];

    _pageController = PageController(initialPage: _currentIndex);

  }

  @override
  Widget build(BuildContext context) {
    //  SafeArea
    return Scaffold(

      appBar: AppBar(
        title:Text(
          _appBarTitle[_currentIndex],
          style: TextStyle(color: Colors.white),
        ),
      ),

      body: PageView.builder(

        // physics: NeverScrollableScrollPhysics(),
        //禁止滑动

        itemBuilder: (BuildContext context, int index) {
          return _pages[index];
        },

        controller: _pageController,
        itemCount: _pages.length,
        onPageChanged: (index) {
          setState(() {
            _currentIndex = index;
          });
        },
      ),

      bottomNavigationBar: BottomNavigationBar(
        
     items: [
      BottomNavigationBarItem(
            icon: Icon(
              Icons.home,
            ),
            activeIcon:  Icon(
              Icons.home,
            ),
            title: Text(
              '首页',
              // style: TextStyle(color: Colors.yellow),
            )),
      BottomNavigationBarItem(
            icon: Icon(
              Icons.email,
            ),
            activeIcon:  Icon(
              Icons.email,
            ),
            title: Text(
              '动态',
              // style: TextStyle(color: Colors.blue),
            )),
      BottomNavigationBarItem(
            icon: Icon(
              Icons.pages,
        
            ),
            activeIcon:  Icon(
              Icons.pages,
            ),
            title: Text(
              '发现',
              // style: TextStyle(color: Colors.blue),
            )),
      BottomNavigationBarItem(
            icon: Icon(
              Icons.airplay,
             
            ),
            activeIcon:  Icon(
              Icons.airplay,
            ),
            title: Text(
              '我的',
              // style: TextStyle(color: Colors.blue),
            )),
      ],

      currentIndex: _currentIndex,

      type: BottomNavigationBarType.fixed,

      // _navigationView.map((view) => view.item).toList(),

      // unselectedItemColor: Colors.yellow,

      //  selectedItemColor: Colors.red,

      onTap: (index) {

        setState(() {
           _currentIndex = index;
        });

        _pageController.animateToPage(index,
              duration: Duration(microseconds: 1), curve: Curves.ease);

      },
      
    ),
      
      drawer: MyDrawerPageWidget(),

    );

  }


}



